package com.foreknow.elm.controller;

import com.foreknow.elm.po.Orders;
import com.foreknow.elm.service.Impl.OrderServiceImpl;
import com.foreknow.elm.service.OrderService;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class OrderController {
    public Object createOrders(HttpServletRequest request){
        OrderService orderService=new OrderServiceImpl();
        String userId=request.getParameter("userId");
        Integer businessId=Integer.parseInt(request.getParameter("businessId"));
        Integer daId=Integer.parseInt(request.getParameter("daId"));
        Double orderTotal=Double.parseDouble(request.getParameter("orderTotal"));
        int i=orderService.createOrders(userId,businessId,daId,orderTotal);
        return i;
    }
    /**
     * 根据订单编号查询订单信息，包括所属商家信息，和此订单的所有订单明细信息
     * @return
     */
    public Object getOrdersById(HttpServletRequest request){
        OrderService orderService=new OrderServiceImpl();
        Integer orderId=Integer.parseInt(request.getParameter("orderId"));
        Orders orders=orderService.getOrdersById(orderId);
        return orders;
    }

    /**
     * 根据用户编号查询此用户的所有订单信息
     * @return
     */
    public Object listOrdersByUserId(HttpServletRequest request){
        OrderService orderService=new OrderServiceImpl();
        String userId=request.getParameter("userId");
        List<Orders>list= orderService.listOrdersByUserId(userId);
        return list;
    }
}
